#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
int compare(const void* a1, const void* b1)
{
    return *(int*)a1 - *(int*)b1;
}

int threeSumClosest(int* nums, int numsSize, int target) {
    int min = (nums[0] + nums[1] + nums[2]);
    qsort(nums, numsSize, sizeof(int), compare);
    int res = INT_MAX;
    int sum = 0;
    int left = 0, right = 0;
    for (int i = 0; i < numsSize - 2; i++)
    {
        left = i + 1;
        right = numsSize - 1;
        while (left < right)
        {
            sum = nums[i] + nums[left] + nums[right] - target;
            res = ((abs(sum) < abs(res)) ? sum : res);
            if (sum > 0)
            {
                right--;
            }
            else if (sum < 0)
            {
                left++;
            }
            else
                return target;
        }
    }
    return target + res;
}

int main()
{


	return 0;
}